<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<!-- HTML file produced from file: manual.tex --
 -- using Hyperlatex v 2.3.1 (c) Otfried Cheong--
 -- on Emacs 21.4 (patch 15) "Security Through Obscurity" XEmacs Lucid, Fri Dec  3 20:36:32 2004 -->
<HEAD>
<TITLE>Scheme 48 Manual -- I/O</TITLE>

</HEAD><BODY BGCOLOR="#ffffff">
<EM>Scheme 48 Manual</EM> | <A HREF="s48manual.html#top_node">Contents</A> | In Chapter: <A HREF="s48manual_78.html">Access to POSIX</A><BR>Previous: <A HREF="s48manual_86.html">I/O</A> | Next: <A HREF="s48manual_86.html">I/O</A>
<H2>I/O</H2>
<P>These procedures are in structures <CODE>posix-i/o</CODE> and <CODE>posix</CODE>.
<P><UL><LI><CODE>(open-pipe<I></I>)&nbsp;-&gt;&nbsp;<I>input-port&nbsp;+&nbsp;output-port</I></CODE><A NAME="1">&nbsp;</A>
</UL>
<CODE>Open-pipe</CODE> creates a new pipe and returns the two ends as an
 input port and an output port.
<P>A <EM>file descriptor</EM> port (or <CODE><I>fd-port</I></CODE>)
 is a port that reads to or writes from an OS file descriptor.
Fd-ports are returned by <CODE>open-input-file</CODE>, <CODE>open-output-file</CODE>,
 <CODE>open-file</CODE>, <CODE>open-pipe</CODE>, and other procedures.
<UL><LI><CODE>(fd-port?<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="2">&nbsp;</A>
<LI><CODE>(port-&gt;fd<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>integer&nbsp;or&nbsp;<TT>&nbsp;#f</TT></I></CODE><A NAME="3">&nbsp;</A>
</UL>
<CODE>Fd-port?</CODE> returns true if its argument is an fd-port.
<CODE>Port-&gt;fd</CODE> returns the file descriptor associated with 
 or <CODE>#f</CODE> if <CODE><I>port</I></CODE> is not an fd-port.
<P><UL><LI><CODE>(remap-file-descriptors<I>&nbsp;fd-spec&nbsp;...</I>)</CODE><A NAME="4">&nbsp;</A>
</UL>
<CODE>Remap-file-descriptors</CODE> reassigns file descriptors to ports.
The <CODE><I>fd-specs</I></CODE> indicate which port is to be mapped to each
 file descriptor: the first gets file descriptor <CODE>0</CODE>, the second gets
 <CODE>1</CODE>, and so forth.
A <CODE><I>fd-spec</I></CODE> is either a port that reads from or writes to
 a file descriptor,
 or <CODE>#f</CODE>, with <CODE>#f</CODE> indicating that the corresponding file
 descriptor is not used.
Any open ports not listed are marked `close-on-exec'.
The same port may be moved to multiple new file descriptors.
<P>For example,
<BLOCKQUOTE><PRE>
(remap-file-descriptors (current-output-port)
                        #f
                        (current-input-port))
</PRE></BLOCKQUOTE>
moves the current output port to file descriptor <CODE>0</CODE> and the
current input port to file descriptor <CODE>2</CODE>.
<P><UL><LI><CODE>(dup<I>&nbsp;fd-port</I>)&nbsp;-&gt;&nbsp;<I>fd-port</I></CODE><A NAME="5">&nbsp;</A>
<LI><CODE>(dup-switching-mode<I>&nbsp;fd-port</I>)&nbsp;-&gt;&nbsp;<I>fd-port</I></CODE><A NAME="6">&nbsp;</A>
<LI><CODE>(dup2<I>&nbsp;fd-port&nbsp;file-descriptor</I>)&nbsp;-&gt;&nbsp;<I>fd-port</I></CODE><A NAME="7">&nbsp;</A>
</UL>
These change <CODE><I>fd-port</I></CODE>'s file descriptor and return a new port
 that uses <CODE><I>ports</I></CODE>'s old file descriptor.
<CODE>Dup</CODE> uses the lowest unused file descriptor and <CODE>dup2</CODE> uses the
 one provided.
<CODE>Dup-switching-mode</CODE> is the same as <CODE>dup</CODE> except that the returned
 port is an input port if the argument was an output port and vice
 versa.
If any existing port uses the file descriptor passed to <CODE>dup2</CODE>, that
 port is closed.
<P><UL><LI><CODE>(close-all-but<I>&nbsp;port&nbsp;...</I>)</CODE><A NAME="8">&nbsp;</A>
</UL>
<CODE>Close-all-but</CODE> closes all file descriptors whose associated ports
 are not passed to it as arguments.
<P><UL><LI><CODE>(close-on-exec?<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="9">&nbsp;</A>
<LI><CODE>(set-close-on-exec?!<I>&nbsp;port&nbsp;boolean</I>)</CODE><A NAME="10">&nbsp;</A>
</UL>
<CODE>Close-on-exec?</CODE> returns true if <CODE>port</CODE> will be closed
 when a new program is exec'ed.
<CODE>Set-close-on-exec?!</CODE> sets <CODE>port</CODE>'s close-on-exec flag.
<P><UL><LI><CODE>(i/o-flags<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>file-options</I></CODE><A NAME="11">&nbsp;</A>
<LI><CODE>(set-i/o-flags!<I>&nbsp;port&nbsp;file-options</I>)</CODE><A NAME="12">&nbsp;</A>
</UL>
These two procedures read and write various options for <CODE>port</CODE>.
The options that can be read are <CODE>append</CODE>, <CODE>nonblocking</CODE>,
 <CODE>read-only</CODE>, <CODE>write-only</CODE>, and <CODE>read/write</CODE>.
Only the <CODE>append</CODE> and <CODE>nonblocking</CODE> can be written.
<P><UL><LI><CODE>(port-is-a-terminal?<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>boolean</I></CODE><A NAME="13">&nbsp;</A>
<LI><CODE>(port-terminal-name<I>&nbsp;port</I>)&nbsp;-&gt;&nbsp;<I>string</I></CODE><A NAME="14">&nbsp;</A>
</UL>
<CODE>Port-is-a-terminal?</CODE> returns true if <CODE><I>port</I></CODE> has an underlying
 file descriptor that is associated with a terminal.
For such ports <CODE>port-terminal-name</CODE> returns the name of the
 terminal, for all others it returns <CODE>#f</CODE>.
<P><P>
  
Previous: <A HREF="s48manual_86.html">I/O</A> | Next: <A HREF="s48manual_86.html">I/O</A></BODY></HTML>
